package com.atguigu.educms.controller;


import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author hwt
 * @since 2022-09-12
 */
@RestController
@RequestMapping("educms/admin/banner")
public class BannerAdminController {
    @Resource
    private CrmBannerService bannerService;

    @ApiOperation(value = "分页查询轮播图")
    @GetMapping("pageBanner/{current}/{limit}")
    public R pageBanner(@PathVariable("current") long current,
                        @PathVariable("limit") long limit) {
        Page<CrmBanner> page = new Page<>(current, limit);
        bannerService.page(page, null);
        return R.ok().data("items", page.getRecords()).data("total", page.getTotal());
    }

    @ApiOperation(value = "修改轮播图")
    @PutMapping("update")
    public R updateById(@RequestBody CrmBanner banner) {
        bannerService.updateById(banner);
        return R.ok();
    }

    @ApiOperation(value = "根据id删除轮播图")
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable("id") String id) {
        bannerService.removeById(id);
        return R.ok();
    }

    @ApiOperation(value = "获取Banner")
    @GetMapping("get/{id}")
    public R getBannerById(@PathVariable String id) {
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item", banner);
    }
}

